from _ast import Name
from ast import Assign, NodeVisitor
import typing
INT = 0
FLOAT = 1
STRING = 2


class AssignmentVisitor(NodeVisitor):
    def __init__(self) -> None:
        self.assigned: typing.Dict[str, int] = {}

    def visit_Assign(self, node: Assign) -> typing.Any:
        assert len(node.targets) == 1
        # 只有Name类型才需要分析。
        # 这是因为attribute等类型都是引用，直接修改即可。
        if isinstance(node.targets[0], Name):
            self.assigned[node.targets[0].id] = FLOAT
            self.visit(node.value)

    def get_assigned_values(self, node):
        self.visit(node)
        return self.assigned
